﻿using System.Net;
using System.Net.Mail;
using EzyGoEzySystem.Interfaces;
using System.IO;
using System;

namespace EzyGoEzySystem.Services
{
    /// <summary>
    /// Implematation of IEzyNotification
    /// </summary>
    /// <author>Phan Ngo Hoang An</author>
    public class EzyNotificationService : IEzyNotification
    {
        public bool SendEmail(string senderAddress, string senderName, string recipientAddress, string recipientName,string subject, string body)
        {
            MailAddress sender = new MailAddress(senderAddress, senderName);
            MailAddress recipient = new MailAddress(recipientAddress, recipientName);
            MailMessage mail = new MailMessage(sender,recipient);
            mail.Subject = subject;
            mail.Body = body;
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.Credentials = new NetworkCredential("ezygoezyservice@gmail.com", "Ezygoezy2011");
            client.EnableSsl = true;
            client.Send(mail);
            return true;
        }

        public bool SendSMS(string phoneNo, string message)
        {
            string url = String.Format("http://127.0.0.1:2511/newmessage?empf=Customer[{0}];&text={1}&type=send", phoneNo, message);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream resStream = response.GetResponseStream();
            return true;
        }
    }
}